/*
 * @Author: gaolulu 1402328525@qq.com
 * @Date: 2024-12-16 15:32:41
 * @LastEditors: gaolulu 1402328525@qq.com
 * @LastEditTime: 2025-04-07 11:52:12
 * @FilePath: \insurance_policy_inspect_h5\src\assets\js\globalMethods\globalButtonPoind.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

//针对按钮的埋点  主要采取自定义指令方式
// directives/focus.ts  
import { DirectiveBinding, VNode } from 'vue';  

// 为 logButtonName 指令添加类型支持  
const typedLogButtonName = {  
  // ...logButtonName,  
  beforeMount(el: HTMLElement, binding: DirectiveBinding<any>) {  
    const buttonName = binding.value || 'Unknown Button';  
      
    // 定义一个唯一的标识符来存储事件处理函数，避免重复添加或移除错误的事件处理函数  
    const handler = () => {  
      //埋点事件走的方法
      // 请求参数处理
      const isJstLogin = sessionStorage.getItem('jstJointLoginVo')
      let sendMessage = {
        'module_name':isJstLogin?'保单检视_金事通':'保单检视_H5',
        'module_icon_name':buttonName
      }
      console.log(sendMessage,"*********");
      //发送埋点事件
      // _XFLOW_.pushEvent(['click','click_public','点击',sendMessage,function(){}])
    };  
      
    // 存储事件处理函数到元素上，以便可以在 unmounted 时正确移除  
    (el as any).__vueClick__ = handler;  
    el.addEventListener('click', handler);  
  },  
  unmounted(el: HTMLElement) {  
    const handler = (el as any).__vueClick__;  
    if (handler) {  
      el.removeEventListener('click', handler);  
      delete (el as any).__vueClick__;  
    }  
  }  
};  
// const 
  
// 导出指令集合  
export const directives = {  
  logButtonName: typedLogButtonName  
};

// 使用方法
// v-log-button-name="'Cancel Button'" 